<?php
 
namespace app\admin\validate;
use think\Validate; 
use app\admin\model\Invite as InviteModel;

class Invite extends Validate{
    // 验证规则
    protected $rule = [
        ['inviter_id', 'require', '邀请人必须'],
        ['invitee_id', 'require|unique:invite|different:inviter_id|checkUser', '被邀请人必须|被邀请人唯一|不能邀请自己|不能邀请自己的邀请人'],
    ];  

    // 自定义验证规则
    protected function checkUser($value,$rule,$data)
    {
        $where['inviter_id'] = $data['invitee_id'];
        $where['invitee_id'] = $data['inviter_id'];
        return InviteModel::get($where) ? false : true;
    }
}